package com.module.app.pop;

import android.content.Context;
import android.graphics.Color;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.module.app.adapter.holder.MenuMoreHolder;
import com.module.app.adapter.holder.MenuMoreHolder;
import com.module.app.bean.MenuMoreBean;
import com.module.base.base.adapter.BaseAdapter;
import com.module.base.base.adapter.BaseNewAdapter;
import com.module.app.bean.MenuMoreBean;
import com.module.base.base.adapter.BaseViewHolder;
import com.module.base.utils.CollectionUtil;
import com.module.base.utils.RecycleViewUtil;
import com.lxj.xpopup.animator.PopupAnimator;
import com.lxj.xpopup.animator.TranslateAnimator;
import com.lxj.xpopup.core.AttachPopupView;
import com.lxj.xpopup.enums.PopupAnimation;
import com.module.app.R;

import java.util.List;

/**
 * @author bsnl_yanxuwen
 * @date 2020/11/4 18:19
 * Description :
 * 订单更多
 */
public class MenuMorePop extends AttachPopupView {

    RecyclerView recyclerview;

    public BaseAdapter baseNewAdapter = new BaseAdapter() {
        @Override
        public BaseViewHolder onCreateDefaultViewHolder(ViewGroup parent, int viewType) {
            return new MenuMoreHolder(parent);
        }
    };

    public interface OnItemClickListener {
        void onItemClick(MenuMoreHolder holder, MenuMoreBean bean);
    }

    public MenuMorePop(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.app_pop_menu_more;
    }

    public void setData(List<MenuMoreBean> list, OnItemClickListener listener) {
        if (CollectionUtil.isEmptyOrNull(list)) {
            dismiss();
            return;
        }
        baseNewAdapter.setNewData(list);
        baseNewAdapter.setOnItemClickListener(new BaseNewAdapter.OnItemClickListener<MenuMoreHolder, MenuMoreBean>() {
            @Override
            public void onItemClick(MenuMoreHolder holder, MenuMoreBean bean) {
                if (listener != null) {
                    listener.onItemClick(holder, bean);
                }
                dismiss();
            }
        });
    }


    @Override
    protected void onCreate() {
        super.onCreate();
        recyclerview = findViewById(R.id.recyclerview);
        recyclerview.setLayoutManager(RecycleViewUtil.getLinear(getContext()));
        baseNewAdapter.bindToRecyclerView(recyclerview);
    }


    @Override
    public void doAttach() {
        super.doAttach();
        attachPopupContainer.setBackgroundColor(Color.TRANSPARENT);
    }

    @Override
    protected PopupAnimator getPopupAnimator() {
        return new TranslateAnimator(getPopupImplView(), 500, isShowUp ?
                PopupAnimation.TranslateFromBottom : PopupAnimation.TranslateFromTop);
    }


    @Override
    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
    }
}
